@page "/"
@using ValidationWithDataAnnotations.Models

<Row>
    <Column>
        <Validations @ref="@ValidationsRef" Mode="ValidationMode.Manual" Model="@EmployeeModel" ValidateOnLoad="false">
            <Fields>
                <Validation>
                    <Field ColumnSize="ColumnSize.IsHalf">
                        <FieldLabel>First Name</FieldLabel>
                        <FieldBody>
                            <TextEdit @bind-Text="@EmployeeModel.FirstName">
                                <Feedback>
                                    <ValidationError />
                                </Feedback>
                            </TextEdit>
                        </FieldBody>
                    </Field>
                </Validation>
                <Validation>
                    <Field ColumnSize="ColumnSize.IsHalf">
                        <FieldLabel>Last Name</FieldLabel>
                        <FieldBody>
                            <TextEdit @bind-Text="@EmployeeModel.LastName">
                                <Feedback>
                                    <ValidationError />
                                </Feedback>
                            </TextEdit>
                        </FieldBody>
                    </Field>
                </Validation>
            </Fields>
            <Fields>
                <Validation>
                    <Field ColumnSize="ColumnSize.IsHalf">
                        <FieldLabel>Email Address</FieldLabel>
                        <FieldBody>
                            <TextEdit @bind-Text="@EmployeeModel.Email" Role="TextRole.Email">
                                <Feedback>
                                    <ValidationError />
                                </Feedback>
                            </TextEdit>
                        </FieldBody>
                    </Field>
                </Validation>
                <Validation>
                    <Field ColumnSize="ColumnSize.IsHalf">
                        <FieldLabel>Date of Birth</FieldLabel>
                        <FieldBody>
                            <DatePicker @bind-Date="@EmployeeModel.DateOfBirth">
                                <Feedback>
                                    <ValidationError />
                                </Feedback>
                            </DatePicker>
                        </FieldBody>
                    </Field>
                </Validation>
            </Fields>
            <Fields>
                <Validation>
                    <Field ColumnSize="ColumnSize.IsHalf">
                        <FieldLabel>Years of Experience</FieldLabel>
                        <FieldBody>
                            <NumericPicker @bind-Value="@EmployeeModel.YearsOfExperience">
                                <Feedback>
                                    <ValidationError />
                                </Feedback>
                            </NumericPicker>
                        </FieldBody>
                    </Field>
                </Validation>
                <Validation>
                    <Field ColumnSize="ColumnSize.IsHalf">
                        <FieldLabel>Gender</FieldLabel>
                        <FieldBody>
                            <Select @bind-SelectedValue="@EmployeeModel.Gender">
                                <ChildContent>
                                    <SelectItem TValue="string"></SelectItem>
                                    @foreach ( var g in Gender.GetGenders() )
                                    {
                                        <SelectItem TValue="string" Value="@g.Code">@g.Name</SelectItem>
                                    }
                                </ChildContent>
                                <Feedback>
                                    <ValidationError />
                                </Feedback>
                            </Select>
                        </FieldBody>
                    </Field>
                </Validation>
            </Fields>
            <Validation>
                <Field>
                    <FieldLabel>Address</FieldLabel>
                    <FieldBody>
                        <TextEdit @bind-Text="@EmployeeModel.Address.Street">
                            <Feedback>
                                <ValidationError />
                            </Feedback>
                        </TextEdit>
                    </FieldBody>
                </Field>
            </Validation>
            <Fields>
                <Validation>
                    <Field ColumnSize="ColumnSize.IsHalf">
                        <FieldLabel>City</FieldLabel>
                        <FieldBody>
                            <Select @bind-SelectedValue="@EmployeeModel.Address.City">
                                <ChildContent>
                                    <SelectItem TValue="string"></SelectItem>
                                    @foreach ( var c in City.GetCities() )
                                    {
                                        <SelectItem TValue="string" Value="@c.Code">@c.Name</SelectItem>
                                    }
                                </ChildContent>
                                <Feedback>
                                    <ValidationError />
                                </Feedback>
                            </Select>
                        </FieldBody>
                    </Field>
                </Validation>
                <Validation>
                    <Field ColumnSize="ColumnSize.IsHalf">
                        <FieldLabel>Zip</FieldLabel>
                        <FieldBody>
                            <TextEdit @bind-Text="@EmployeeModel.Address.Zip">
                                <Feedback>
                                    <ValidationError />
                                </Feedback>
                            </TextEdit>
                        </FieldBody>
                    </Field>
                </Validation>
            </Fields>
            <Validation>
                <Field>
                    <FieldLabel>Country</FieldLabel>
                    <FieldBody>
                        <Select @bind-SelectedValue="@EmployeeModel.Address.Country">
                            <ChildContent>
                                <SelectItem TValue="string"></SelectItem>
                                @foreach ( var c in Country.GetCountries() )
                                {
                                    <SelectItem TValue="string" Value="@c.Code">@c.Name</SelectItem>
                                }
                            </ChildContent>
                            <Feedback>
                                <ValidationError />
                            </Feedback>
                        </Select>
                    </FieldBody>
                </Field>
            </Validation>
        </Validations>
        <Button Color="Color.Primary" Clicked="@OnSaveClicked">
            Validate and Submit
        </Button>
    </Column>
</Row>
@code {
    [Inject] IMessageService MessageService { get; set; }

    Validations ValidationsRef { get; set; }

    Employee EmployeeModel { get; set; } = new Employee();

    async Task OnSaveClicked()
    {
        if ( await ValidationsRef.ValidateAll() )
        {
            await MessageService.Info( "Thank you for filling the form." );

            await ValidationsRef.ClearAll();
        }
    }
}